﻿package {
	import flash.events.Event;
	import flash.display.MovieClip;
	import flash.display.Sprite;

	public class enemy extends Sprite {
		private var core:Object;

		// construtor
		public function enemy() {
			addEventListener(Event.ADDED_TO_STAGE, onadd);
		}

		private function onadd(e:Event) {
			core=MovieClip(root);
			addEventListener(Event.ENTER_FRAME, loop);
		}

		private function loop(e:Event) {
			y+=2;
			for (var i:int = 0; i < core.bulletholder.numChildren; i++) {
				var bulletTarget:Sprite=core.bulletholder.getChildAt(i);
				if (hitTestObject(bulletTarget)) {
					core.bulletholder.getChildAt(i).removeListeners();
					core.bulletholder.removeChild(bulletTarget);

					removeEventListener(Event.ENTER_FRAME, loop);
					core.removeChild(this);
				}
			}
		}

		public function removeListeners():void {
			removeEventListener(Event.ENTER_FRAME, loop);
		}
	}
}